package pass;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Random;
import java.util.regex.Pattern;

/**
 * 用户名工具
 *
 * @author ningzhaoyun
 */
public class UserNameUtil {

    private static Integer MAXLENGTH = 20;
    private static String NAMEREG = "^([\u4e00-\u9fa5]{2,20})$";
    private static String NAMEEXREG = "^[\u4E00-\u9FA5]{1,19}[\u25CF\u00B7][\u4E00-\u9FA5]{1,19}$";

    private UserNameUtil() {
    }

    public static boolean checkName(String name){
        if(name.length() > MAXLENGTH){
            return false;
        }
        return Pattern.matches(NAMEREG, name) || Pattern.matches(NAMEEXREG, name);
    }

    public static void main(String[] args) {
        String name = "你";
        System.out.println(name + " : " + Pattern.matches(NAMEREG, name));
        System.out.println(name + " : " + Pattern.matches(NAMEEXREG, name));

        name = "你你";
        System.out.println(name + " : " + Pattern.matches(NAMEREG, name));
        System.out.println(name + " : " + Pattern.matches(NAMEEXREG, name));

        name = "·你";
        System.out.println(name + " : " + Pattern.matches(NAMEREG, name));
        System.out.println(name + " : " + Pattern.matches(NAMEEXREG, name));
        name = "你·";
        System.out.println(name + " : " + Pattern.matches(NAMEREG, name));
        System.out.println(name + " : " + Pattern.matches(NAMEEXREG, name));
        name = "你·你";
        System.out.println(name + " : " + Pattern.matches(NAMEREG, name));
        System.out.println(name + " : " + Pattern.matches(NAMEEXREG, name));
    }
}
